package io.renren.modules.workmanagement.utils;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author dongyuhao
 */
public class PojoUtils {
    public static <T,R> List<R> streamMapList(List<T> list, Function<? super T, ? extends R> mapper){
        return list.stream().map(mapper).collect(Collectors.toList());
    }
    public static <T,R> Set<R> streamMapSet(List<T> list, Function<? super T, ? extends R> mapper){
        return list.stream().map(mapper).collect(Collectors.toSet());
    }

    public static <T,K,V> Map<K,V> listToMap(List<T> list,Function<? super T, ? extends K> keyMapper,
                                             Function<? super T, ? extends V> valueMapper){
        return list.stream().collect(Collectors.toMap(keyMapper, valueMapper));
    }

    public static <T,K> Map<K,List<T>> listGroupByKey(List<T> list,Function<? super T, ? extends K> classifier){
        return list.stream().collect(Collectors.groupingBy(classifier));
    }
}
